from functools import wraps
def coroutine(func):

    @wraps(func)
    def primer(*args,**kwargs): ➊
        gen = func(*args,**kwargs) ➋
        next(gen) ➌
        return gen ➍
    return primer



from coroutil import coroutine
@coroutine
def averager():
    total = 0.0
    count = 0
    average = None
        while True:
        term = yield average
        total += term
        count += 1
        average = total/count
